wayland: Move DnD grab breaking function into gdkdevice-wayland.c
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 1 Jun 2015 13:55:20 +0000 (14:55 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 2 Jun 2015 16:09:49 +0000 (18:09 +0200)
This has little to do with GdkDragContext, and a lot to do with
the GdkDevice that triggered it, seems to make more sense in
gdkdevice-wayland.c.

gdk/wayland/gdkdevice-wayland.c
gdk/wayland/gdkdnd-wayland.c
gdk/wayland/gdkprivate-wayland.h
gdk/wayland/gdkselection-wayland.c

index 23197ad54ce4e5085405402c27393108625d666e..9ef8968b7529ecd39a6e85f93abf307e88bed740 100644 (file)
@@ -707,12 +707,7 @@ data_device_drop (void                  *data,
   local_dnd_owner = gdk_selection_owner_get_for_display (device->display, gdk_drag_get_selection (device->drop_context));
 
   if (local_dnd_owner)
-    {
-      GdkDragContext *source_context;
-
-      source_context = gdk_wayland_drag_context_lookup_by_source_window (local_dnd_owner);
-      gdk_wayland_drag_context_undo_grab (source_context);
-    }
+    gdk_wayland_device_unset_grab (device->pointer);
 
   _gdk_wayland_drag_context_emit_event (device->drop_context,
                                         GDK_DROP_START, GDK_CURRENT_TIME);
@@ -2103,3 +2098,57 @@ gdk_wayland_device_set_selection (GdkDevice             *gdk_device,
   wl_data_device_set_selection (device->data_device, source,
                                 _gdk_wayland_display_get_serial (display_wayland));
 }
+
+void
+gdk_wayland_device_unset_grab (GdkDevice *gdk_device)
+{
+  GdkWaylandDeviceData *device;
+  GdkEventSequence *sequence;
+  GdkModifierType state;
+  GdkEvent *event;
+  guint button;
+  gdouble x, y;
+
+  device = GDK_WAYLAND_DEVICE (gdk_device)->device;
+  _gdk_wayland_device_get_last_implicit_grab_serial (GDK_WAYLAND_DEVICE (gdk_device), &sequence);
+  gdk_window_get_device_position_double (device->pointer_grab_window,
+                                         gdk_device, &x, &y, &state);
+
+  if (sequence)
+    {
+      event = gdk_event_new (GDK_TOUCH_END);
+      event->touch.window = g_object_ref (device->pointer_grab_window);
+      event->touch.send_event = TRUE;
+      event->touch.sequence = sequence;
+      event->touch.time = GDK_CURRENT_TIME;
+      event->touch.x = event->touch.x_root = x;
+      event->touch.y = event->touch.y_root = y;
+    }
+  else if (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))
+    {
+      if (state & GDK_BUTTON1_MASK)
+        button = 1;
+      else if (state & GDK_BUTTON2_MASK)
+        button = 2;
+      else if (state & GDK_BUTTON3_MASK)
+        button = 3;
+      else
+        return;
+
+      event = gdk_event_new (GDK_BUTTON_RELEASE);
+      event->button.window = g_object_ref (device->pointer_grab_window);
+      event->button.send_event = TRUE;
+      event->button.button = button;
+      event->button.time = GDK_CURRENT_TIME;
+      event->button.x = event->button.x_root = x;
+      event->button.y = event->button.y_root = y;
+    }
+  else
+    return;
+
+  device->button_modifiers = 0;
+  gdk_event_set_device (event, gdk_device);
+  gdk_event_set_source_device (event, gdk_device);
+
+  _gdk_wayland_display_deliver_event (gdk_device_get_display (gdk_device), event);
+}
index 9936e54c49769b2ba3c3142cf90124ae7f064764..fea4480c06dfbc213dd3bb81896e332873d9f165 100644 (file)
@@ -463,59 +463,6 @@ gdk_wayland_drag_context_get_data_source (GdkDragContext *context)
   return GDK_WAYLAND_DRAG_CONTEXT (context)->data_source;
 }
 
-void
-gdk_wayland_drag_context_undo_grab (GdkDragContext *context)
-{
-  GdkEventSequence *sequence;
-  GdkModifierType state;
-  GdkDevice *device;
-  GdkEvent *event;
-  guint button;
-  gdouble x, y;
-
-  device = gdk_drag_context_get_device (context);
-  _gdk_wayland_device_get_last_implicit_grab_serial (GDK_WAYLAND_DEVICE (device), &sequence);
-  gdk_window_get_device_position_double (gdk_drag_context_get_source_window (context),
-                                         device, &x, &y, &state);
-
-  if (sequence)
-    {
-      event = gdk_event_new (GDK_TOUCH_END);
-      event->touch.window = g_object_ref (gdk_drag_context_get_source_window (context));
-      event->touch.send_event = TRUE;
-      event->touch.sequence = sequence;
-      event->touch.time = GDK_CURRENT_TIME;
-      event->touch.x = event->touch.x_root = x;
-      event->touch.y = event->touch.y_root = y;
-    }
-  else if (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))
-    {
-      if (state & GDK_BUTTON1_MASK)
-        button = 1;
-      else if (state & GDK_BUTTON2_MASK)
-        button = 2;
-      else if (state & GDK_BUTTON3_MASK)
-        button = 3;
-      else
-        return;
-
-      event = gdk_event_new (GDK_BUTTON_RELEASE);
-      event->button.window = g_object_ref (gdk_drag_context_get_source_window (context));
-      event->button.send_event = TRUE;
-      event->button.button = button;
-      event->button.time = GDK_CURRENT_TIME;
-      event->button.x = event->button.x_root = x;
-      event->button.y = event->button.y_root = y;
-    }
-  else
-    return;
-
-  gdk_event_set_device (event, device);
-  gdk_event_set_source_device (event, device);
-
-  _gdk_wayland_display_deliver_event (gdk_device_get_display (device), event);
-}
-
 GdkWindow *
 gdk_wayland_drag_context_get_dnd_window (GdkDragContext *context)
 {
index cd2e171980013d95821f59bffbbb842e71754a5c..beb489a8c0abf8a61abd0dc019b1fec400b1cfdf 100644 (file)
@@ -125,8 +125,6 @@ GdkDragContext * gdk_wayland_drag_context_lookup_by_data_source   (struct wl_dat
 GdkDragContext * gdk_wayland_drag_context_lookup_by_source_window (GdkWindow *window);
 struct wl_data_source * gdk_wayland_drag_context_get_data_source  (GdkDragContext *context);
 
-void gdk_wayland_drag_context_undo_grab (GdkDragContext *context);
-
 void gdk_wayland_drop_context_update_targets (GdkDragContext *context);
 
 void _gdk_wayland_display_create_window_impl (GdkDisplay    *display,
@@ -187,6 +185,8 @@ struct wl_data_device * gdk_wayland_device_get_data_device (GdkDevice *gdk_devic
 void gdk_wayland_device_set_selection (GdkDevice             *gdk_device,
                                        struct wl_data_source *source);
 
+void gdk_wayland_device_unset_grab       (GdkDevice        *device);
+
 void gdk_wayland_device_unset_touch_grab (GdkDevice        *device,
                                           GdkEventSequence *sequence);
 
index 5fc2c210fba58248843ec6cb24a577205380751d..a2b83ba40c27ebf95b5281da36e896a4a2fed68e 100644 (file)
@@ -651,7 +651,7 @@ data_source_send (void                  *data,
 
   if (context)
     {
-      gdk_wayland_drag_context_undo_grab (context);
+      gdk_wayland_device_unset_grab (gdk_drag_context_get_device (context));
       _gdk_wayland_drag_context_emit_event (context, GDK_DROP_FINISHED,
                                             GDK_CURRENT_TIME);
     }
@@ -679,7 +679,7 @@ data_source_cancelled (void                  *data,
       context = gdk_wayland_drag_context_lookup_by_data_source (source);
 
       if (context)
-        gdk_wayland_drag_context_undo_grab (context);
+        gdk_wayland_device_unset_grab (gdk_drag_context_get_device (context));
     }
   else if (source == wayland_selection->clipboard_source)
     gdk_wayland_selection_unset_data_source (display, atoms[ATOM_CLIPBOARD]);